package com.billdowney.qq.robot.util;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class MapUtil {
    public static Map<String, Object> getObjectToMap(Object obj) throws IllegalAccessException {
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        Class<?> clazz = obj.getClass();
        System.out.println(clazz);
        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);
            String fieldName = field.getName();
            Object value = field.get(obj);
            if (value == null) {
                value = "";
            }
            map.put(fieldName, value);
        }
        return map;

    }
public static Map<String,String> getMap (Object obj) throws IllegalAccessException {
    Map<String, Object> myMap = MapUtil.getObjectToMap(obj);
    Map<String, String> Map1 = new HashMap<>();
    myMap.forEach((k, v) -> {
        if (v != null && v != "")
            Map1.put(k, v + "");
    });
    return Map1;
}
}
